#include "VistaFichaTablero.h"
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include "Constantes.h"

void VistaFichaTablero::CrearImagenes() {
    std::string path;
    Glib::RefPtr<Gdk::Pixbuf> unBuffer, unBufferAux;

    path = RUTA_BLUE_MINIBAR_H_GRANDE;

    unBuffer= Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarBlueH.push_back(unBufferAux);
    }

    path = RUTA_RED_MINIBAR_H_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarRedH.push_back(unBufferAux);
    }

    path = RUTA_GREEN_MINIBAR_H_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarGreenH.push_back(unBufferAux);
    }

    path = RUTA_VIOLET_MINIBAR_H_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarVioletH.push_back(unBufferAux);
    }

    path = RUTA_YELLOW_MINIBAR_H_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarYellowH.push_back(unBufferAux);
    }

    /* Minibars verticales */
    path = RUTA_BLUE_MINIBAR_V_GRANDE;

    unBuffer= Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarBlueV.push_back(unBufferAux);
    }

    path = RUTA_RED_MINIBAR_V_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarRedV.push_back(unBufferAux);
    }

    path = RUTA_GREEN_MINIBAR_V_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarGreenV.push_back(unBufferAux);
    }

    path = RUTA_VIOLET_MINIBAR_V_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarVioletV.push_back(unBufferAux);
    }

    path = RUTA_YELLOW_MINIBAR_V_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersMiniBarYellowV.push_back(unBufferAux);
    }


    /* Buttons */
    path = RUTA_BLUE_BUTTON_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersButtonBlue.push_back(unBufferAux);;
    }

    path = RUTA_RED_BUTTON_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersButtonRed.push_back(unBufferAux);;
    }

    path = RUTA_VIOLET_BUTTON_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersButtonViolet.push_back(unBufferAux);;
    }

    path = RUTA_GREEN_BUTTON_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersButtonGreen.push_back(unBufferAux);;
    }

    path = RUTA_YELLOW_BUTTON_GRANDE;

    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersButtonYellow.push_back(unBufferAux);;
    }

    path = RUTA_GOLDENSTAR_GRANDE;
    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersGolden.push_back(unBufferAux);;
    }

    path = RUTA_HUECO_GRANDE;
    unBuffer = Gdk::Pixbuf::create_from_file(path.c_str());

    for (int i = 50; i > 4; i--) {
        unBufferAux = unBuffer->scale_simple(i, i, Gdk::INTERP_BILINEAR);
        VistaFichaTablero::buffersHueco.push_back(unBufferAux);;
    }
}

VistaFichaTablero::VistaFichaTablero(std::string color,
                                     bool visible, int x, int y) {
    this->x = x;
    this->y = y;
    this->color = color;
    this->visible = visible;
    this-> xDesde = ajustarCoordenada(x);
    this-> yDesde = ajustarCoordenada(y);
}

int VistaFichaTablero::ajustarCoordenada(int unaCoordenada) {
    int coordAjustada = 0;
    coordAjustada = unaCoordenada * 50 + ((unaCoordenada + 1) * 3);
    coordAjustada += 50; //es el margen
return coordAjustada;
}

std::string VistaFichaTablero::getType() {
    return tipo + " " + color;
}

VistaFichaTablero::~VistaFichaTablero() {
}

std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersButtonBlue;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersButtonYellow;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersButtonGreen;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersButtonRed;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersButtonViolet;

std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarBlueV;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarYellowV;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarGreenV;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarRedV;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarVioletV;

std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarBlueH;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarYellowH;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarGreenH;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarRedH;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersMiniBarVioletH;

std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersGolden;
std::vector<Glib::RefPtr<Gdk::Pixbuf> >  VistaFichaTablero::buffersHueco;

std::map<std::string, std::map<std::string,
                std::vector<Glib::RefPtr<Gdk::Pixbuf> > > >imagenes;
